home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
ClipBoard.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-24
|
2KB
|
98 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "ClipBoard.h"
#include "Class.h"
#include "View.h"
#include "MemBuf.h"
#include "WindowSystem.h"
#include "Data.h"
#include "String.h"
//---- ClipBoard ---------------------------------------------------------------
NewMetaImpl(ClipBoard,Object, (TP(data)));
ClipBoard::ClipBoard()
{
data= 0;
}
ClipBoard::~ClipBoard()
{
SafeDelete(data);
}
void ClipBoard::SetData(Data *d)
{
SafeDelete(data);
data= d;
}
bool ClipBoard::CanPaste(View *v)
{
gWindowSystem->DevCheckSelection();
if (v && data)
return v->CanPaste(data);
return FALSE;
}
void ClipBoard::SelectionToClipboard(Object *op, bool makecopy)
{
if (makecopy && op)
op= op->DeepClone();
if (op) {
SetData(new ObjectData(op));
gWindowSystem->DevHaveSelection(data);
}
}
extern bool gPaste;
Command *ClipBoard::PasteClipboard(View *v)
{
if (v && data) {
gPaste= TRUE;
v->PasteData(data);
gPaste= FALSE;
return v->PasteData(data);
}
return gNoChanges;
}
char *ClipBoard::GetExtSelection(int *retlen, Symbol type, Class *want)
{
char *buf= 0;
*retlen= 0;
if (data) {
if (gDebug)
fprintf(stderr, "ClipBoard::GetExtSelection: %s\n", type.AsString());
if (want == 0)
want= Meta(Object);
Object *op= data->AsObject(want);
if (op) {
if (type == cDocTypeET) {
MemBuf *mb= new MemBuf;
OStream os(mb);
os << op;
os.flush();
mb->SwitchToRead();
*retlen= (int) mb->ContentsSize();
buf= mb->Base();
}
if (type == cDocTypeAscii) {
buf= op->AsString();
if (buf)
*retlen= strlen(buf);
}
SafeDelete(op);
}
}
return buf;
}